OUTPUT_dir <- TRADING_FIGS

plant_period_data <- read_dta(str_c(TRADING_DATA_CLEAN, "panel_plant-period.dta"))

pre_post_covid_data <- plant_period_data %>%
  select(gpcb_id, period_num, emission_val_prorated, permit_alloc_prorated) %>%
  mutate(net_demand = emission_val_prorated - permit_alloc_prorated) %>% 
  mutate(post_covid = period_num>=7)

covid_net_demand_reg <- pre_post_covid_data %>%
  group_by(gpcb_id, post_covid) %>%
  summarize(mean_net_demand= mean(net_demand)) %>%
  pivot_wider(names_from = "post_covid", values_from = "mean_net_demand") %>%
  filter(abs(`FALSE`)<2000 & abs(`TRUE`)<2000) %>%
  ggplot(aes(x=`FALSE`, y= `TRUE`))+
  xlab("Pre-Covid Industry Net-Demand")+
  ylab("Post-Covid Industry Net-Demand")+
  geom_point(color="dodgerblue", shape=1)+
  geom_smooth(aes(linetype="OLS"), method="lm", formula=y~x, se=F, color="black")+
  geom_abline(aes(linetype="y = x", slope=1, intercept=0),show.legend=F)+
  theme_classic()+
  scale_linetype_manual(values=c(1,3), name="")
  
ggsave(str_c(OUTPUT_dir, "Figure_F2.pdf"),
       covid_net_demand_reg,
       height = 4,
       width = 6,
       units = "in")
